import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
  // {
  //   path:'/register',
  //   component:()=>import('@/views/table/register'),
  //   hidden:true
  // }



  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   // meta: { title: '主页', icon: 'dashboard' },
  //   children: [{
  //     path: 'dashboard',
  //     name: 'Dashboard',
  //     component: () => import('@/views/dashboard/index'),
  //     meta: { title: '主页', icon: 'dashboard' }
  //   }]
  // },

  // {
  //   path: '/authManager',
  //   component: Layout,
  //   redirect: '/authManager/userManager',
  //   name: 'AuthManager',
  //   meta: { title: '权限管理', icon: 'example' ,role:['admin']},
  //   children: [
  //     {
  //       path: 'userManager',
  //       name: 'userManager',
  //       component: () => import('@/views/auth/userManager'),
  //       meta: { title: '用户管理', icon: 'user' }
  //     },
  //     {
  //       path: 'roleManager',
  //       name: 'roleManager',
  //       component: () => import('@/views/auth/roleManager'),
  //       meta: { title: '角色管理', icon: 'user' }
  //     },
  //     {
  //       path: 'menuManager',
  //       name: 'menuManager',
  //       component: () => import('@/views/auth/menuManager'),
  //       meta: { title: '菜单管理', icon: 'user' }
  //     },
  //     {
  //       path: 'authTree',
  //       name: 'authTree',
  //       component: () => import('@/views/auth/authTree'),
  //       meta: { title: '权限树', icon: 'tree' }
  //     }
  //   ]
  // },

  // {
  //   path: '/resourceManager',
  //   component: Layout,
  //   redirect: '/resourceManager/sellerManager',
  //   name: 'resourceManager',
  //   meta: { title: '资源管理', icon: 'example' ,role:['admin','editor']},
  //   children: [
  //     {
  //       path: 'sellerManager',
  //       name: 'sellerManager',
  //       component: () => import('@/views/table/sellerManager'),
  //       meta: { title: '商家管理', icon: 'form' }
  //     },
  //     {
  //       path: 'costumerManager',
  //       name: 'costumerManager',
  //       component: () => import('@/views/table/costumerManager'),
  //       meta: { title: '客户管理', icon: 'user' }
  //     },
  //     {
  //       path: 'serviceProManager',
  //       name: 'serviceProManager',
  //       component: () => import('@/views/table/serviceProManager'),
  //       meta: { title: '服务管理', icon: 'example' }
  //     }
  //   ]
  // },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]


/**
 * asyncRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed asyncRoutes
 */
export const asyncRoutes = [
  // {
  //   path: '/login',
  //   component: () => import('@/views/login/index'),
  //   hidden: true
  // },

  // {
  //   path: '/404',
  //   component: () => import('@/views/404'),
  //   hidden: true
  // },



  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    // meta: { title: '主页', icon: 'dashboard' },
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/user/personalCenter'),
      meta: {
        title: '主页',
        icon: 'dashboard'
      }
    }]
  },
  // --------------------------------------------------------------------------------
  {
    path: '/doctor',
    component: Layout,
    redirect: '/doctor/checkAppointment',
    name: 'doctor',
    meta: {
      title: '预约审核',
      icon: 'user',
      roles: ['main_doctor', 'doctor']
    },
    children: [{
      path: 'checkAppointment',
      name: 'checkAppointment',
      component: () => import('@/views/doctor/checkAppointment'),
      meta: {
        title: '患者预约审核',
        icon: 'table',
        roles: ['main_doctor', 'doctor']
      }
    }]
  },
  // {
  //   path: '/user',
  //   component: Layout,
  //   redirect: '/user/personalCenter',
  //   name: 'user',
  //   meta: {
  //     title: '个人中心',
  //     icon: 'user',
  //     roles: ['main_doctor', 'doctor','main_nurse','nurse','casher','hr','medical','patient']
  //   },
  //   children: [{
  //     path: 'personalCenter',
  //     name: 'personalCenter',
  //     component: () => import('@/views/user/personalCenter'),
  //     meta: {
  //       title: '个人信息',
  //       icon: 'user',
  //       roles: ['main_doctor', 'doctor','main_nurse','nurse','casher','hr','medical','patient']
  //     }
  //   },
  //   ]
  // },
  {
    path: '/doctor',
    component: Layout,
    redirect: '/doctor/patientDetail',
    name: 'doctor',
    meta: {
      title: '患者信息管理',
      icon: 'user',
      roles: ['main_doctor', 'doctor']
    },
    children: [{
        path: 'patientDetail',
        name: 'patientDetail',
        component: () => import('@/views/doctor/doctorPatientManager'),
        meta: {
          title: '患者信息',
          icon: 'table',
          roles: ['main_doctor', 'doctor','super_admin']
        }
      },
      {
        path: 'medicalAdviceManager',
        name: 'medicalAdviceManager',
        component: () => import('@/views/doctor/medacialAdviceManager'),
        meta: {
          title: '患者医嘱管理',
          icon: 'nested',
          roles: ['main_doctor', 'doctor','super_admin']
        }
      },
      {
        path: 'drugListManager',
        name: 'drugListManager',
        component: () => import('@/views/doctor/drugListManager'),
        meta: {
          title: '患者处方管理',
          icon: 'example',
          roles: ['main_doctor', 'doctor','super_admin']
        }
      },
      {
        path: 'otherListManager',
        name: 'otherListManager',
        component: () => import('@/views/doctor/otherListManager'),
        meta: {
          title: '患者其他项目管理',
          icon: 'example',
          roles: ['main_doctor', 'doctor','super_admin']
        }
      },
      {
        path: 'medicalRecordManager',
        name: 'medicalRecordManager',
        component: () => import('@/views/doctor/medicalRecordManager'),
        meta: {
          title: '患者病案管理',
          icon: 'form',
          roles: ['main_doctor', 'doctor','super_admin']
        }
      }
    ]
  },
  // {
  //   path: '/drugManager',
  //   component: Layout,
  //   redirect: '/drugManager/costDrugManager',
  //   name: 'newsManager',
  //   meta: {
  //     title: '药房管理',
  //     icon: 'example',
  //     roles: ['medical','doctor','main_doctor']
  //   },
  //   children: [{
  //       path: 'draDrugManager',
  //       name: 'draDrugManager',
  //       component: () => import('@/views/drug/draDrugManager'),
  //       meta: {
  //         title: '退药',
  //         icon: 'example',
  //         roles: ['medical','doctor','main_doctor']
  //       }
  //     }]
  // },
    {
    path: '/consultation',
    component: Layout,
    redirect: '/consultation/consultationApplication',
    name: 'consultation',
    meta: {
      title: '会诊管理',
      icon: 'user',
      roles: ['main_doctor', 'doctor','super_admin']
    },
    children: [{
      path: 'consultationApplication',
      name: 'consultationApplication',
      component: () => import('@/views/doctor/consultationApplication'),
      meta: {
        title: '患者会诊详情',
        icon: 'table',
        roles: ['main_doctor', 'doctor','super_admin']
      }
    },
      {
        path: 'myConsultation',
        name: 'myConsultation',
        component: () => import('@/views/doctor/myConsultation'),
        meta: {
          title: '我的会诊',
          icon: 'form',
          roles: ['doctor','super_admin']
        }
      }],
  },
  {
    path: '/doctor',
    component: Layout,
    redirect: '/doctor/checkTrans',
    name: 'checkTrans',
    meta: {
      title: '患者转科审核',
      icon: 'example',
      roles: ['doctor','main_doctor','super_admin']
    },
    children: [{
      path: 'checkTrans',
      name: 'checkTrans',
      component: () => import('@/views/doctor/checkTrans'),
      meta: {
        title: '患者转科审核',
        icon: 'example',
        roles: ['doctor','main_doctor','super_admin']
      }
    }]
  },


  {
    path: '/nurseManager',
    component: Layout,
    redirect: '/nurseManager/nurseManager',
    name: 'newsManager',
    meta: {
      title: '护士站管理',
      icon: 'example',
      roles: ['nurse','main_nurse','super_admin']
    },
    children: [{
      path: 'hospitalApplication',
      name: 'hospitalApplication',
      component: () => import('@/views/nurse/hospitalApplication'),
      meta: {
        title: '出入院申请',
        icon: 'dashboard',
        roles: ['nurse','main_nurse','super_admin']
      }
    },
    {
      path: 'room',
      name: 'room',
      component: () => import('@/views/nurse/room'),
      meta: {
        title: '床位处理',
        icon: 'example',
        roles: ['nurse','main_nurse','super_admin']
      }
    },
    {
      path: 'medicalAdvice',
      name: 'medicalAdvice',
      component: () => import('@/views/nurse/medicalAdvice'),
      meta: {
        title: '医嘱处理',
        icon: 'nested',
        roles: ['nurse','main_nurse','super_admin']
      }
    },
    {
      path: 'nurseRecord',
      name: 'nurseRecord',
      component: () => import('@/views/nurse/nurseRecord'),
      meta: {
        title: '护理记录',
        icon: 'form',
        roles: ['nurse','main_nurse','super_admin']
      }
    },
    {
      path: 'queryPatientOfHospital',
      name: 'queryPatientOfHospital',
      component: () => import('@/views/nurse/queryPatientOfHospital'),
      meta: {
        title: '查询系统',
        icon: 'eye-open',
        roles: ['nurse','main_nurse','super_admin']
      }
    },
    {
      path: 'gotoOtherDepartment',
      name: 'gotoOtherDepartment',
      component: () => import('@/views/nurse/gotoOtherDepartment'),
      meta: {
        title: '转科',
        icon: 'eye',
        roles: ['main_nurse','super_admin']
      }
    }
  ]
  },


  {
    path: '/drugManager',
    component: Layout,
    redirect: '/drugManager/costDrugManager',
    name: 'newsManager',
    meta: {
      title: '药房管理',
      icon: 'example',
      roles: ['medical','doctor','main_doctor','super_admin']
    },
    children: [{
        path: 'costDrugManager',
        name: 'costDrugManager',
        component: () => import('@/views/drug/costDrugManager'),
        meta: {
          title: '发药',
          icon: 'user',
          roles: ['medical','super_admin']
        }
      },
      {
        path: 'draDrugManager',
        name: 'draDrugManager',
        component: () => import('@/views/drug/draDrugManager'),
        meta: {
          title: '退药',
          icon: 'user',
          roles: ['medical','doctor','main_doctor']
        }
      },
      {
        path: 'drugManager',
        name: 'drugManager',
        component: () => import('@/views/drug/drugManager'),
        meta: {
          title: '药品信息',
          icon: 'user',
          roles: ['medical','super_admin']
        }
      }
    ]
  },



  // {
  //   path: '/newsManager',
  //   component: Layout,
  //   redirect: '/newsManager/newsinfoManager',
  //   name: 'newsManager',
  //   meta: {
  //     title: '新闻管理',
  //     icon: 'example',
  //     roles: ['super_admin', 'news_admin','news_editor']
  //   },
  //   children: [{
  //       path: 'newsinfoManager',
  //       name: 'newsinfoManager',
  //       component: () => import('@/views/news/newsinfoManager'),
  //       meta: {
  //         title: '新闻内容管理',
  //         icon: 'user',
  //         roles: ['super_admin', 'news_admin','news_editor']
  //       }
  //     },
  //     {
  //       path: 'newscategoryManager',
  //       name: 'newscategoryManager',
  //       component: () => import('@/views/news/newscategoryManager'),
  //       meta: {
  //         title: '新闻分类管理',
  //         icon: 'user',
  //         roles: ['super_admin', 'news_admin']
  //       }
  //     },
  //     {
  //       path: 'newscommentManager',
  //       name: 'newscommentManager',
  //       component: () => import('@/views/news/newscommentManager'),
  //       meta: {
  //         title: '新闻评论管理',
  //         icon: 'user',
  //         roles: ['super_admin', 'news_admin']
  //       }
  //     }
  //   ]
  // },

  {
    path: '/costManager',
    component: Layout,
    redirect: '/costManager/costManager',
    name: 'costAllManager',
    meta: {
      title: '费用管理',
      icon: 'example',
      roles: ['casher','super_admin']
    },
    children: [{
      path: 'costManager',
      name: 'costManager',
      component: () => import('@/views/cost/costManager'),
      meta: {
        title: '总费用',
        icon: 'user',
        roles: ['casher','super_admin']
      }
    },{
      path: 'costDrugDetailManager',
      name: 'costDrugDetailManager',
      component: () => import('@/views/cost/costDrugDetailManager'),
      meta: {
        title: '药品费用',
        icon: 'user',
        roles: ['casher','super_admin']
      }
    },
      {
        path: 'costOtherDetailManager',
        name: 'costOtherDetailManager',
        component: () => import('@/views/cost/costOtherDetailManager'),
        meta: {
          title: '其他费用',
          icon: 'user',
          roles: ['casher','super_admin']
        }
      },
      {
        path: 'patientDetailManager',
        name: 'patientDetailManager',
        component: () => import('@/views/cost/patientDetailManager'),
        meta: {
          title: '病人详情',
          icon: 'user',
          roles: ['casher','super_admin']
        }
      },
      {
        path: 'cardManager',
        name: 'cardManager',
        component: () => import('@/views/cost/cardManager'),
        meta: {
          title: '医疗卡',
          icon: 'user',
          roles: ['casher','super_admin']
        }
      },
      {
        path: 'cardOutDetailManager',
        name: 'cardOutDetailManager',
        component: () => import('@/views/cost/cardOutDetailManager'),
        meta: {
          title: '医疗卡消费记录',
          icon: 'user',
          roles: ['casher','super_admin']
        }
      }
    ]
  },




  {
    path: '/patientManager',
    component: Layout,
    redirect: '/patientManager/appointmentManager',
    name: 'patientManager',
    // meta: {
    //   title: '挂号',
    //   icon: 'example',
    //   roles: ['patient','super_admin']
    // },
    // children: [{
    //   path: 'appointmentManager',
    //   name: 'appointmentManager',
    //   component: () => import('@/views/table/appointmentManager'),
    //   meta: {
    //     title: '挂号预约',
    //     icon: 'user'
    //   }
    // }
    //
    // ]
  },
  {
    path: '/HrManager',
    component: Layout,
    redirect: '/HrManager/personManager',
    name: 'HrManager',
    meta: {
      title: '人事管理',
      icon: 'example',
      roles: ['hr','super_admin']
    },
    children: [{
      path: 'personManager',
      name: 'personManager',
      component: () => import('@/views/hr/personManager'),
      meta: {
        title: '人员信息',
        icon: 'user'
      }
    },
      {
        path: 'addUserManager',
        name: 'addUserManager',
        component: () => import('@/views/hr/addUserManager'),
        meta: {
          title: '信息录入',
          icon: 'user'
        }
      },
      {
        path: 'scheduling',
        name: 'scheduling',
        component: () => import('@/views/hr/scheduling'),
        meta: {
          title: '排班日常',
          icon: 'user'
        }
      },

    ]
  }



  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]


const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
